import md5 from '@/js_sdk/js-md5/src/md5.js'
// const apiKey = 'test'
// const apiSecret = 'test'
const apiKey = 'app64a38f52f0a2f'
const apiSecret = 'C2A6186F180C60497897AFB7F051D096'

export function encryption(dic) {
	// var dic = {}
	dic['app_key'] = apiKey
	dic['req_time'] = Date.parse(new Date()) / 1000
	var newData = ''
	var arr = Object.keys(dic)
	arr = arr.sort()

	for (var key in arr) {
		key = arr[key]
		newData = newData + key + '=' + dic[key]
	}
	const enData = md5(apiSecret + newData + apiSecret, '').substring(0, 32).toUpperCase()

	// let mdEnData = md5(enData)
	// enData = mdEnData.substring(0, 32).toUpperCase()

	dic['sign'] = enData

	return dic
}

export const encryptionNew = (dic) => {
	const appSecret = process.env.NODE_ENV === 'development' ? 'test' : '1D73FEE27CB91463436FFD1B3D425C94'
	dic['reqTime'] = Date.parse(new Date()) / 1000
	let newData = ''
	let arr = Object.keys(dic)
	arr = arr.sort()

	for (let key in arr) {
		key = arr[key]
		newData = newData + key + '=' + dic[key]
	}
	let enData = appSecret + newData + appSecret
	enData = md5(enData, '')
	enData = enData.substring(0, 32).toUpperCase()

	dic['sign'] = enData

	return dic
}